package com.warski.wonderfires.page.device;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.warski.wonderfires.R;
import com.warski.wonderfires.dlna.model.DeviceInfo;

/**
 * Created by xuhaiping on 2020/8/29.
 * 菜单数据
 */
public class SearchDeviceAdaopter extends ArrayAdapter<DeviceInfo> {
    private LayoutInflater inflater;
    private Context context;

    public SearchDeviceAdaopter(Context context) {
        super(context, 0);
        this.context = context;
        inflater = LayoutInflater.from(this.context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.common_list_item, null);
        }
        DeviceInfo deviceInfo = getItem(position);

        ImageView icon = convertView.findViewById(R.id.menuicon);
        if(deviceInfo.isConnected()){
            icon.setBackgroundResource(R.mipmap.soundbox_connected);
        }
        else {
            icon.setBackgroundResource(R.mipmap.soundbox_with_color);
        }
        TextView text = convertView.findViewById(R.id.menutext);
        text.setText(deviceInfo.getName());
        return convertView;
    }

}
